package com.dingding.transfer.stamper.handler;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangxiyuan
 * @description
 * @createDate 2021/4/6 15:31
 **/
@Component
@Slf4j
public class TaskInstanceProcessorRegistry {
    private List<TaskInstanceProcessor> list = new ArrayList<>();

    @Autowired
    private UseStamperInstance useStamperInstance;

    @Autowired
    private FingerAddInstance fingerAddInstance;

    @Autowired
    private PushRecordInstance pushRecordInstance;

    @PostConstruct
    public void init(){
        list.add(useStamperInstance);
        list.add(fingerAddInstance);
        list.add(pushRecordInstance);
    }

    public void handleInstance(JSONObject jsonObject){
        list.stream().forEach(taskInstanceProcessor -> {
            try {
                taskInstanceProcessor.handleTask(jsonObject);
            } catch (Exception e) {
                log.error("审批实例处理任务出现错误，{}",e.getMessage());
            }
        });
    }
}
